home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / PRGMMING / CNVLIB.ZIP / DATEDIFF.CMM < prev    next >
Encoding:
Text File  |  1994-11-25  |  1.2 KB  |  54 lines

  1. // DateDiff.cmm - Display differences in dates where dates are
  2. // ver.2          in MM/DD/YYYY format
  3.  
  4. SecondsPerDay = 60 * 60 * 24;
  5.  
  6. main(argc,argv)
  7. {
  8.    if ( argc != 3 ) {
  9.       printf("\aDateDiff - display difference in dates\n");
  10.       printf("USAGE: CEnvi DateDiff MM/DD/YY MM/DD/YY\n");
  11.       ByeBye();
  12.    }
  13.  
  14.    Time1 = GetTimeFromDateString(argv[1]);
  15.    Time2 = GetTimeFromDateString(argv[2]);
  16.  
  17.    DiffTime = Time2 - Time1;
  18.    DiffDay = DiffTime / SecondsPerDay;
  19.    printf("Date difference is %d days\n",DiffDay);
  20. }
  21.  
  22. GetTimeFromDateString(String)
  23. {
  24.    if ( 3 != sscanf(String,"%d/%d/%d",Month,Day,Year) ) {
  25.       printf("\aUnrecognized date \"%s\"\n",argv[1]);
  26.       ByeBye();
  27.    }
  28.    if ( Year < 1000 ) {
  29.       Year += ( Year < 20 ) ? 2000 : 1900 ;
  30.    }
  31.  
  32.    // convert to time
  33.    tm.tm_year = Year - 1900;
  34.    tm.tm_mon = Month - 1;
  35.    tm.tm_mday = Day;
  36.    ResultTime = mktime(tm);
  37.    if ( ResultTime < 1 ) {
  38.       printf("%d/%d/%d is not within range of dates I can calculate.\n",
  39.              Month,Day,Year);
  40.       ByeBye();
  41.    }
  42.    return ResultTime;
  43. }
  44.  
  45. ByeBye()
  46. {
  47.    if defined(_WINDOWS_) && !defined(_SHELL_) {
  48.       printf("press any key to exit...");
  49.       getch();
  50.    }
  51.    exit(EXIT_FAILURE);
  52. }
  53.  
  54.